import { service } from './service'
import { http_config } from './config'

const { default_headers } = http_config

const request = (option: any) => {
    console.log(option);
    const { url, method, params, data, headersType, responseType, loadingMsg, headers,isShow } = option
    const message = loadingMsg ? loadingMsg :'请稍后...'
    const showLoading = isShow ? isShow : true
    // @ts-ignore
    // @ts-ignore
    return service({
        url: url,
        method,
        params,
        data,
        responseType: responseType,
        headers: {
            'Accept-Language': JSON.parse(localStorage.getItem("language")) || 'zh-CN,zh;q=0.9',
            'Content-Type': headersType || default_headers,
            ...headers
        },
        message,
        showLoading
    })
}

export default {
    get: <T = any>(option: any) => {
        return request({ method: 'get', ...option }) as unknown as T
    },
    post: <T = any>(option: any) => {
        return request({ method: 'post', ...option }) as unknown as T
    },
    delete: <T = any>(option: any) => {
        return request({ method: 'delete', ...option }) as unknown as T
    },
    put: <T = any>(option: any) => {
        return request({ method: 'put', ...option }) as unknown as T
    }
}